package com.heima.wemedia.listen;


import com.alibaba.fastjson.JSON;
import com.heima.common.constants.UserConstants;
import com.heima.model.user.pojos.ApUser;
import com.heima.wemedia.service.WmUserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class AuditListen {
    @Autowired
    private WmUserService wmUserService;
    /**
     * 监听这个topic 通过审核后，添加信息到wm_user表中
     * @param message
     */
    @KafkaListener(topics = UserConstants.PASS_AUDIT_KAFKA)
    public void onMessage(String message){
        log.info("监听到消息：{}",message);
        //1、非空判断
        if (StringUtils.isNotBlank(message)) {
          //2、反序列化成原来对象
            ApUser apUser = JSON.parseObject(message, ApUser.class);
            //3、交给逻辑层处理
            wmUserService.auditPass(apUser);
        }
    }
}
